//
//  JTLoginRegisterViewController.m
//  百思不得姐
//
//  Created by Robin Zhang on 2016/12/18.
//  Copyright © 2016年 BeiJingWangDianJieTong. All rights reserved.
//

#import "JTLoginRegisterViewController.h"

@interface JTLoginRegisterViewController ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftMargin;

@end

@implementation JTLoginRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
}

- (UIStatusBarStyle)preferredStatusBarStyle { // iOS7.0开始，苹果允许你使用控制器设置状态栏样式
    
    return UIStatusBarStyleLightContent;
}

/**
 * 关闭当前界面
 */
- (IBAction)close:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

/**
 * 显示登录\注册界面
 */
- (IBAction)showLoginOrRegister:(UIButton *)sender {
   
    // 退出键盘
    [self.view endEditing:YES];
    
    if (self.leftMargin.constant) { // 目前显示的是注册界面，点击按钮后要切换为登录界面
        
        [self.leftMargin setConstant:0];
        [sender setTitle:@"注册账号" forState:UIControlStateNormal];
    }
    else { // 目前显示的是登录界面，点击按钮后要切换为注册界面
        
        [self.leftMargin setConstant:-self.view.jt_width];
        [sender setTitle:@"已有账号?" forState:UIControlStateNormal];
    }
    
    JTWeak(self)
    // 动画
    [UIView animateWithDuration:0.25 animations:^{
        // UI的刷新代码：修改UI界面的代码
        
        // 强制刷新：让最新设置的约束值马上作用到UI控件上
        // 会刷新到self.view内部的所有子控件
        [weak_self.view layoutIfNeeded];
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
}

@end
